package com.mobileservice.autoreply.activity;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.widget.ToggleButton;

import com.mobileservice.autoreply.R;
import com.mobileservice.autoreply.base.BaseActivity;
import com.mobileservice.autoreply.common.constant.CommConstant;
import com.mobileservice.autoreply.ui.customizeui.CustomTextViewBold;
import com.mobileservice.autoreply.ui.customizeui.TopBar;

public class SettingActivity extends BaseActivity {

	private ToggleButton auto_block_sms, auto_block_call, auto_reply;
	private SharedPreferences preferences;
	private CustomTextViewBold caption;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting_layout);
		baseActivity = this;
		/** Toggle Button for Turn on Turn Off */
		auto_block_call = (ToggleButton) findViewById(R.id.block_call_tglbtn);
		auto_block_sms = (ToggleButton) findViewById(R.id.block_sms_tglbtn);
		auto_reply = (ToggleButton) findViewById(R.id.Auto_sms_tglbtn);
		topBar = (TopBar) findViewById(R.id.topBar);
		caption = (CustomTextViewBold) topBar.findViewById(R.id.caption);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		IntializeValueAuto();
	}

	private void IntializeValueAuto() {
		preferences = getSharedPreferences(CommConstant.PREFS, MODE_PRIVATE);
		
		auto_block_call.setChecked(preferences.getBoolean(CommConstant.BLOCK_CALL_PREFS, false));
		auto_block_sms.setChecked(preferences.getBoolean(CommConstant.BLOCK_SMS_PREFS, false));
		auto_reply.setChecked(preferences.getBoolean(CommConstant.AUTO_REPLY_PREFS, false));
		caption.setText("Settings");
	}

	private class SaveTask extends BaseLoading {
		@Override
		protected Void doInBackground(Void... arg0) {
			// TODO Auto-generated method stub
			preferences = getSharedPreferences(CommConstant.PREFS, MODE_PRIVATE);
			Editor editor = preferences.edit();
			editor.putBoolean(CommConstant.BLOCK_CALL_PREFS, auto_block_call.isChecked());
			editor.putBoolean(CommConstant.BLOCK_SMS_PREFS, auto_block_sms.isChecked());
			editor.putBoolean(CommConstant.AUTO_REPLY_PREFS, auto_reply.isChecked());
			editor.commit();
			return super.doInBackground(arg0);

		}
	}

	public void Save() {
		new SaveTask().execute();
	}

}
